Axios.defaults.baseURL = project + '/onlineArchive/transfer/division';
let main ={
    el:"#app",
    data:function() {
        return {
            spotCheckResult:[],
            spotCheckResultDialogVisible:false,
            spotCheckResultOptions:[],
            archivalStatus:{},
            loading_1:false,
            loading_2:false,
            loading_3:false,
            loading_4:false,
            loading_5:false,
            activeName: 'first',
            dialogTableVisible:false,
            toBeReceivedDivisionStatus:'',
            archivalStatusList:[],
            archivalTypeList:[],
            /*acceptTheCenterList :[],*/
            incomingWayList:[],
            toBeReceivedStatisticsDTOList:[],
            toBeReceivedStatisticsDTOStoreCodes:[],
            toBeReceivedStatisticsDTOStoreName:'',
            toBeReceivedDetailList:[],
            toBeReceivedDetailIds:[],
            toBeReceivedDetailSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                storeCode:'',
                keyword:''
            },
            acceptedToBeArchivedList:[],
            acceptedToBeArchivedSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                transferDeputyTime:[],
                keyword:''
            },
            acceptedToBeArchivedIds:[],
            archivedList:[],
            archivedSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                transferDeputyTime:[],
                keyword:''
            },
            archivedIds:[],
            spotCheckingList:[],
            spotCheckingSearch:{
                pagination:{
                    pageNum: 1,
                    pageSize: 10,
                    total:0,
                },
                applicationDate:[],
                loanTime:[],
                applicationNo:'',
                customerName:'',
                productName:'',
                incomingWay:'',
                insuredName:'',
                archivalType:'',
                archivalStatus:'',
                transferDeputyTime:[],
                keyword:''
            },
            spotCheckingIds:[],
            searchArea:{
                toBeReceivedStatisticsDTOTable:{
                    height:40,
                    isSimple:true
                },
                acceptedToBeArchivedTable:{
                    height:40,
                    isSimple:true
                },
                archivedTable:{
                    height:40,
                    isSimple:true
                },
                spotCheckingTable:{
                    height:40,
                    isSimple:true
                }
            },
        }
    },
    beforeMount:function(){
        this.init();
    },
    computed: {
        // 计算属性的 getter
        tableHeight: function () {
            let height = window.parent.document.getElementById('content-main').clientHeight;
            let that = this;
            return {
                toBeReceivedStatisticsDTOTable:height - that.searchArea.toBeReceivedStatisticsDTOTable.height- 125,
                acceptedToBeArchivedTable:height - that.searchArea.acceptedToBeArchivedTable.height- 125,
                archivedTable:height - that.searchArea.archivedTable.height- 125,
                spotCheckingTable:height - that.searchArea.spotCheckingTable.height- 125,
            }
        }
    },
    methods:{

        /**
         * 重置查询条件
         * @param table
         */
        resetSearch: function (table) {
            if (table == 'acceptedToBeArchivedTable') {
                this.acceptedToBeArchivedSearch = {
                    pagination:{
                        pageNum: 1,
                        pageSize: 10,
                        total:0,
                    },
                    applicationDate:[],
                    loanTime:[],
                    applicationNo:'',
                    customerName:'',
                    productName:'',
                    incomingWay:'',
                    insuredName:'',
                    archivalType:'',
                    archivalStatus:'',
                    transferDeputyTime:[],
                    keyword:''
                };
                this.initAcceptedToBeArchivedPageList();
                return;
            } else if (table == 'archivedTable') {
                this.archivedSearch = {
                    pagination:{
                        pageNum: 1,
                        pageSize: 10,
                        total:0,
                    },
                    applicationDate:[],
                    loanTime:[],
                    applicationNo:'',
                    customerName:'',
                    productName:'',
                    incomingWay:'',
                    insuredName:'',
                    archivalType:'',
                    archivalStatus:'',
                    transferDeputyTime:[],
                    keyword:''
                };
                this.initArchivedPageList();
                return;
            } else if (table == 'spotCheckingTable') {
                this.spotCheckingSearch = {
                    pagination:{
                        pageNum: 1,
                        pageSize: 10,
                        total:0,
                    },
                    applicationDate:[],
                    loanTime:[],
                    applicationNo:'',
                    customerName:'',
                    productName:'',
                    incomingWay:'',
                    insuredName:'',
                    archivalType:'',
                    archivalStatus:'',
                    transferDeputyTime:[],
                    keyword:''
                };
                this.initSpotCheckingPageList();
                return;
            } else {
                return;
            }
        },

        /**
         * 展开  收缩查询区域
         * @param table
         */
        showclick:function(table){
            this.searchArea[table].isSimple = !this.searchArea[table].isSimple;
            let that =this;
            setTimeout(function () {
                that.searchArea[table].height = window.document.getElementById(table).clientHeight ;
            },500)
        },
        init: function () {
            let that = this;
            axios.all([getArchivalStatusList(), getArchivalTypeList(), getIncomingWayList(), getArchivalStatus(), getSpotCheckResultList()])
                .then(axios.spread(function (archivalStatusList, archivalTypeList, incomingWayList, archivalStatus, spotCheckResult) {
                    that.archivalStatusList = archivalStatusList.data.data;
                    that.archivalTypeList = archivalTypeList.data.data;
                    that.incomingWayList = incomingWayList.data.data;
                    that.archivalStatus = archivalStatus.data.data;
                    that.spotCheckResultOptions = spotCheckResult.data.data;
                })).then(function () {
                that.getToBeReceivedStatisticsDTOList();
            });
        },
        /**
         * 获取待接收数据统计列表
         */
        getToBeReceivedStatisticsDTOList:function(){
            let that = this;
            that.loading_1=true;
            Axios.get('/tobeReceived/list')
                .then(function (response) {
                    that.loading_1=false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.toBeReceivedStatisticsDTOList = response.data;
                })
                .catch(function (error) {
                    that.loading_1=false;
                    noticeFailure(that);
                });
        },
        /**
         * 数据表格复选框选择数据
         * @param selection
         */
        toBeReceivedStatisticsDTOTableSelectionChange:function(selection){
            console.log(selection)
            this.toBeReceivedStatisticsDTOStoreCodes = selection.map(function(x){return x.orgId});
            let storeNames = selection.map(function(x){return x.orgName});
            console.log(storeNames)
            if (null == storeNames || storeNames.length == 0 ){
                this.toBeReceivedStatisticsDTOStoreName = '';
            }
            else{
                this.toBeReceivedStatisticsDTOStoreName = storeNames[0];
            }
        },
        /**
         * 获取待接收数据详情列表（档案记录，根据分部)
         */
        getToBeReceivedDetailList:function(){
            this.toBeReceivedDetailSearch.storeCode = this.toBeReceivedStatisticsDTOStoreCodes[0];
            let that = this;
            that.loading_2 = true;
            Axios({
                    method: 'post',
                    url: '/tobeReceived/pageDetailList',
                    data: that.toBeReceivedDetailSearch
                })
                .then(function (response) {
                    that.loading_2 = false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.toBeReceivedDetailList = response.data.list;
                    that.toBeReceivedDetailSearch.pagination.total = response.data.total;
                })
                .catch(function (error) {
                    that.loading_2 = false;
                    noticeFailure(that);
                });
        },
        /**
         * 初始化查看详情数据列表，（加载第一页数据）
         */
        initToBeReceivedDetailPageList:function(){
            this.toBeReceivedDetailList = [];
            this.toBeReceivedDetailTablePageNumChange(1);
        },
        /**
         * 查看详情列表 ，页码改变时触发
         * @param pageNum
         */
        toBeReceivedDetailTablePageNumChange:function(pageNum){
            this.toBeReceivedDetailSearch.pagination.pageNum = pageNum;
            this.getToBeReceivedDetailList();
        },
        /**
         * 查看详情数据列表，每页条数改变时触发
         * @param pageSize
         */
        toBeReceivedDetailTablePageSizeChange:function(pageSize){
            this.toBeReceivedDetailSearch.pagination.pageNum = 1;
            this.toBeReceivedDetailSearch.pagination.pageSize = pageSize;
            this.getToBeReceivedDetailList();
        },
        /**
         * 渲染  查看详情列表 复选框是否可选
         * @param row
         * @param index
         * @returns {boolean}
         */
        toBeReceivedDetailTableIsOptional:function(row,index){
            if (row.archivalStatus == this.archivalStatus.to_be_received_division && row.divisionInSpotChecking != true){
                return true;
            }
            else {
                return false;
            }
        },
        /**
         * 查看详情 列表 复选框选择项改变时触发
         * @param selection
         */
        toBeReceivedDetailTableSelectionChange:function(selection){
            this.toBeReceivedDetailIds = selection.map(function(x){return x.id});
        },
        /**
         * 点击确认接收 按钮
         */
        confirmToReceived:function(){
            if (this.toBeReceivedDetailIds.length == 0){
                noticeWarning(this,'还未选择档案');
                return;
            }
            let that = this;
            this.$confirm('本次接收档案：'+ that.toBeReceivedDetailIds.length +'份，请与实物档案核对是否一致！', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(function() {
                Axios({
                    url:'/tobeReceived/accept',
                    data:that.toBeReceivedDetailIds,
                    method:'post',
                }).then(function (response) {
                    if (response.code != 0){
                        noticeFailure(that);
                        return;
                    }
                    that.initToBeReceivedDetailPageList();
                    that.getToBeReceivedStatisticsDTOList();
                    noticeSuccess(that);
                }).catch(function (error) {
                    noticeDataRequestFailure(that);
                })
            });
        },
        /**
         * 点击查看详情页面抽检按钮
         */
        spotCheckingDetail:function(){
            let that =this;
            Axios({
                url:'/archived/spotChecking',
                data:that.toBeReceivedDetailIds,
                method:'post',
            }).then(function (response) {
                if (response.code != 0){
                    noticeFailure(that);
                    return;
                }
                that.initToBeReceivedDetailPageList();
                noticeSuccess(that);
            }).catch(function (error) {
                noticeDataRequestFailure(that);
            })
        },

        /**
         * 点击详情按钮
         */
        divisionDetail: function (row) {
            this.dialogTableVisible = true;
            this.toBeReceivedStatisticsDTOStoreCodes[0] = row.orgId;
            this.toBeReceivedStatisticsDTOStoreName = row.orgName;
            this.initToBeReceivedDetailPageList();
        },
        /**
         * 获取待归档数据详情列表（档案记录，根据分部)
         */
        getAcceptedToBeArchivedList:function(){
            let that = this;
            that.loading_3 = true;
            Axios({
                method: 'post',
                url: '/acceptedToBeArchived/pageList',
                data: that.acceptedToBeArchivedSearch
            })
                .then(function (response) {
                    that.loading_3 = false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.acceptedToBeArchivedList = response.data.list;
                    that.acceptedToBeArchivedSearch.pagination.total = response.data.total;
                })
                .catch(function (error) {
                    that.loading_3 = true;
                    noticeFailure(that);
                });
        },
        /**
         * 初始化待归档数据列表，（加载第一页数据）
         */
        initAcceptedToBeArchivedPageList:function(){
            this.acceptedToBeArchivedTablePageNumChange(1);
        },
        /**
         * 待归档列表 ，页码改变时触发
         * @param pageNum
         */
        acceptedToBeArchivedTablePageNumChange:function(pageNum){
            this.acceptedToBeArchivedSearch.pagination.pageNum = pageNum;
            this.getAcceptedToBeArchivedList();
        },
        /**
         * 待归档数据列表，每页条数改变时触发
         * @param pageSize
         */
        acceptedToBeArchivedTablePageSizeChange:function(pageSize){
            this.acceptedToBeArchivedSearch.pagination.pageNum = 1;
            this.acceptedToBeArchivedSearch.pagination.pageSize = pageSize;
            this.getAcceptedToBeArchivedList();
        },
        /**
         * 待归档 列表 复选框选择项改变时触发
         * @param selection
         */
        acceptedToBeArchivedTableSelectionChange:function(selection){
            this.acceptedToBeArchivedIds = selection.map(function(x){return x.id});
        },
        /**
         * 点击 归档 按钮
         */
        archived:function(){
            if (this.acceptedToBeArchivedIds.length == 0){
                noticeWarning(this,'还未选择档案');
                return;
            }
            let that = this;

            this.$prompt('请输入归档盒号', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(function(data) {
                Axios({
                    url:'/tobeReceived/archived',
                    data:{
                        ids:that.acceptedToBeArchivedIds.join(","),
                        boxNo:data.value
                    },
                    transformRequest: [function (data) {
                        // 对 data 进行任意转换处理
                        return Qs.stringify(data)
                    }],
                    method:'post',
                }).then(function (response) {
                    if (response.code != 0){
                        noticeFailure(that);
                        return;
                    }
                    that.initAcceptedToBeArchivedPageList();
                    noticeSuccess(that);
                }).catch(function (error) {
                    noticeDataRequestFailure(that);
                })
            }).catch(function() {
                noticeFailure(that);
            });

        },
        /**
         * 获取已数据详情列表（档案记录，根据分部)
         */
        getArchivedList:function(){
            let that = this;
            that.loading_4 = true;
            Axios({
                method: 'post',
                url: '/archived/pageList',
                data: that.archivedSearch
            })
                .then(function (response) {
                    that.loading_4 = false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.archivedList = response.data.list;
                    that.archivedSearch.pagination.total = response.data.total;
                })
                .catch(function (error) {
                    that.loading_4 = false;
                    noticeFailure(that);
                });
        },
        /**
         * 初始化已归档数据列表，（加载第一页数据）
         */
        initArchivedPageList:function(){
            this.archivedTablePageNumChange(1);
        },
        /**
         * 已归档列表 ，页码改变时触发
         * @param pageNum
         */
        archivedTablePageNumChange:function(pageNum){
            this.archivedSearch.pagination.pageNum = pageNum;
            this.getArchivedList();
        },
        /**
         * 已归档数据列表，每页条数改变时触发
         * @param pageSize
         */
        archivedTablePageSizeChange:function(pageSize){
            this.archivedSearch.pagination.pageNum = 1;
            this.archivedSearch.pagination.pageSize = pageSize;
            this.getArchivedList();
        },
        /**
         * 已归档 列表 复选框选择项改变时触发
         * @param selection
         */
        archivedTableSelectionChange:function(selection){
            this.archivedIds = selection.map(function(x){return x.id});
        },
        /**
         * 已归档列表 复选框是否可选
         * @param row
         * @param index
         * @returns {boolean}
         */
        archivedTableIsOptional:function(row,index){
            if (row.divisionInSpotChecking){
                return false;
            }
            else {
                return true;
            }
        },
        /**
         * 已归档，点击抽检按钮
         */
        spotChecking:function(){
            let that =this;
            Axios({
                url:'/archived/spotChecking',
                data:that.archivedIds,
                method:'post',
            }).then(function (response) {
                if (response.code != 0){
                    noticeFailure(that);
                    return;
                }
                that.initArchivedPageList();
                noticeSuccess(that);
            }).catch(function (error) {
                noticeDataRequestFailure(that);
            })
        },

        /**
         * 获取抽检列表（档案记录，根据分部)
         */
        getSpotCheckingList:function(){
            let that = this;
            that.loading_5 = true;
            Axios({
                method: 'post',
                url: '/spotChecking/pageList',
                data: that.spotCheckingSearch
            })
                .then(function (response) {
                    that.loading_5 = false;
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.spotCheckingList = response.data.list;
                    that.spotCheckingSearch.pagination.total = response.data.total;
                })
                .catch(function (error) {
                    that.loading_5 = false;
                    noticeFailure(that);
                });
        },
        /**
         * 初始化抽检数据列表，（加载第一页数据）
         */
        initSpotCheckingPageList:function(){
            this.spotCheckingTablePageNumChange(1);
        },
        /**
         * 抽检列表 ，页码改变时触发
         * @param pageNum
         */
        spotCheckingTablePageNumChange:function(pageNum){
            this.spotCheckingSearch.pagination.pageNum = pageNum;
            this.getSpotCheckingList();
        },
        /**
         * 抽检数据列表，每页条数改变时触发
         * @param pageSize
         */
        spotCheckingTablePageSizeChange:function(pageSize){
            this.spotCheckingSearch.pagination.pageNum = 1;
            this.spotCheckingSearch.pagination.pageSize = pageSize;
            this.getSpotCheckingList();
        },
        /**
         * 抽检 列表 复选框选择项改变时触发
         * @param selection
         */
        spotCheckingTableSelectionChange:function(selection){
            this.spotCheckingIds = selection.map(function(x){return x.id});
        },
        /**
         * 抽检列表 复选框是否可选
         * @param row
         * @param index
         * @returns {boolean}
         */
        spotCheckingTableIsOptional:function(row,index){
            if (row.archivalStatus == this.archivalStatus.fallback_division){
                return false;
            }
            else {
                return true;
            }
        },
        /**
         * 抽检通过
         */
        pass:function(){
            let that = this;
            if (this.spotCheckingIds.length == 0){
                noticeWarning(that,'还未选择档案');
                return;
            }

            this.$confirm('请确认抽检合格', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(function() {
                Axios({
                    url:'/spotChecking/pass',
                    data:that.spotCheckingIds,
                    method:'post',
                }).then(function (response) {
                    if (response.code != 0){
                        noticeFailure(that);
                        return;
                    }
                    that.initSpotCheckingPageList();
                    noticeSuccess(that);
                }).catch(function (error) {
                    noticeDataRequestFailure(that);
                })
            });
        },
        /**
         * 回退
         */
        fallback:function(){
            if (this.spotCheckingIds.length == 0){
                noticeWarning(this,'还未选择档案');
                return;
            }
            if (this.spotCheckingIds.length > 1){
                noticeWarning(this,'每次只能选择一个档案回退');
                return;
            }
            let that = this;
            this.$prompt('请填写回退原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(function(data) {
                Axios({
                    method: 'post',
                    url: '/spotChecking/fallback',
                    data: {
                        id:that.spotCheckingIds[0],
                        reason:data.value
                    },
                    transformRequest: [function (data) {
                        // 对 data 进行任意转换处理
                        return Qs.stringify(data)
                    }],
                })
                    .then(function (response) {
                        if (response.code != 0){
                            noticeDataRequestFailure(that);
                            return;
                        }
                        noticeSuccess(that);
                        that.initSpotCheckingPageList();
                    })
                    .catch(function (error) {
                        noticeFailure(that);
                    });
            })
        },
        /**
         * 点击抽检结果按钮的操作
         */
        handleSpotCheckResult:function(){
            if (this.spotCheckingIds.length == 0){
                noticeWarning(this,'还未选择档案');
                return;
            }
            this.spotCheckResult = [];
            this.spotCheckResultDialogVisible = true;
        },
        /**
         * 保存档案抽检结果
         */
        saveSpotCheckingResult:function(){
            if (this.spotCheckResult.length == 0){
                noticeWarning(this,'未选择抽检结果');
                return;
            }
            let that = this;
            Axios({
                method: 'post',
                url: '/spotChecking/saveSpotCheckingResult',
                data: {
                    ids:that.spotCheckingIds.join(","),
                    results:that.spotCheckResult.join(";")
                },
                transformRequest: [function (data) {
                    // 对 data 进行任意转换处理
                    return Qs.stringify(data)
                }],
            })
                .then(function (response) {
                    if (response.code != 0){
                        noticeDataRequestFailure(that);
                        return;
                    }
                    that.spotCheckResultDialogVisible = false;
                    noticeSuccess(that);
                    that.initSpotCheckingPageList();
                })
                .catch(function (error) {
                    noticeFailure(that);
                });
        },


        /**
         * 日期列格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        dateTimeFormatter:function(row, column, cellValue, index){
            return dateFormatter(cellValue);
        },
        /**
         * 是否格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        booleanFormatter:function(row,column,cellValue,index){
            return booleanFormatter(cellValue);
        },
        /**
         * 日期列格式化,格式化为  YYYY-MM
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        dateTimeFormatterYearMonth:function(row, column, cellValue, index) {
            if (cellValue == null || cellValue == ''){
                return '';
            }
            return moment(cellValue).format('YYYY-MM');
        },
        /**
         * 档案状态格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         */
        archivalStatusFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalStatusList.length ; i++){
                if (this.archivalStatusList[i].code == cellValue){
                    return this.archivalStatusList[i].description;
                }
            }
            return "";
        },

        /**
         * 档案类型格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        archivalTypeFormatter:function(row,column,cellValue,index){
            for(let i = 0 ; i < this.archivalTypeList.length ; i++){
                if (this.archivalTypeList[i].code == cellValue){
                    return this.archivalTypeList[i].value;
                }
            }
            return "";
        },
        /**
         * 进件方式格式化
         * @param row
         * @param column
         * @param cellValue
         * @param index
         * @returns {string|*}
         */
        incomingWayFormatter:function(row, column, cellValue, index){
            for(let i = 0 ; i < this.incomingWayList.length ; i++){
                if (this.incomingWayList[i].code == cellValue){
                    return this.incomingWayList[i].value;
                }
            }
            return "";
        },

        /**
         * 点击tab页切换时执行
         * @param tab
         */
        tabClick:function(tab){
            if (tab.name == 'first') {
                this.getToBeReceivedStatisticsDTOList()
                return;
            }
            if (tab.name == 'second') {
                this.initAcceptedToBeArchivedPageList();
                return;
            }
            if (tab.name == 'third') {
                this.initArchivedPageList();
                return;
            }
            if (tab.name == 'fourth'){
                this.initSpotCheckingPageList();
                return;
            }
        }
    }
}
new Vue(main);